package com.tang.model.template.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/9/1 6:55
 * @Desc
 * @Remarks
 */
public class TOrderMapper extends JDBCTemplate {

    public List<TOrder> selectAll() {
        return super.execQuery("select * from t_order", new RowMapper<TOrder>() {
            @Override
            public TOrder mapRow(ResultSet resultSet, int rowNum) throws SQLException {
                TOrder tOrder = new TOrder();
                tOrder.setId(resultSet.getLong(1));
                tOrder.setOrderNo(resultSet.getString(2));
                tOrder.setUserId(resultSet.getLong(3));
                tOrder.setPhoneId(resultSet.getLong(4));
                LocalDateTime ldt = LocalDateTime.of(resultSet.getDate(5).toLocalDate(), resultSet.getTime(5).toLocalTime());
                tOrder.setCreatedDate(ldt);
                return tOrder;
            }
        }, null);

    }
}
